//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//


#ifndef plDATA_OBJECT_H
#define plDATA_OBJECT_H


//Sqlite3 includes
#include <sqlite3.h>

//Our datatypes
class plData;
class plDatabase;
/*
#include "plLongLong.h"
#include "plDouble.h"
#include "plInt.h"
#include "plString.h"
#include "plPointer.h"
#include "plList.h"
#include "plBool.h"
*/

//Stl includes
#include <list>

//Our Object factor
//#include "plFactoryElement.h"
class plFactoryElement;

class plObject {

public:

    //Constructor
    plObject();

    //Destructor
    virtual ~plObject();

    //Deletes the object from memory
    void DeleteMemory();

    //Gets the database id for this object
    sqlite_int64 Id() const;

    //Sets the database id for the object - Only in subclass
    void SetId(sqlite_int64 id);

    //Indexes the a column for fast searching
    void Index(plData* column);

    //Gets the database for all the objects
    static plDatabase* GetDatabase();

    //For runtime typing - Defind in subclass using defines
    //Get's the classes name - Used by the database as the table name
    virtual const char* _GetClassName() = 0;

    static const int BadId;

private:
    //The database id for this object
    sqlite_int64 TableId;

    //Indexed Columns
    std::list<plData*>* IndexedColumns;

protected:	
    //Creates the object in the database
    virtual void CreateObject();

    //Deletes the object from the database
    virtual void DeleteObject();

}; //end plObject

#include "plFactoryElement.h"

//These defines make it easier to program - database objects
//Declares the the class

//! \file plObject.h
/*!
  \def pl_DECLARE_CLASS
\brief Should be added to the beginning of the class's declartion ie. the *.h
  */
#define pl_DECLARE_CLASS \
        private: \
                    static plFactoryElement _FactoryElement; \
                public: \
                    virtual const char* _GetClassName(); \

/*!
  \def pl_DEFINE_CLASS(className)
\brief Should be added to the beginning of the class definition ie. the *.cpp
*/
#define pl_DEFINE_CLASS(className) \
                    plFactoryElement className::_FactoryElement(#className, &plFactoryElement::ObjectFactoryFunction<className>); \
                    const char*  className::_GetClassName() { return _FactoryElement.GetClassName(); } \



#endif //plObject



